package dao.impl;

import dao.BaseDao;
import dao.SysScheduleDao;
import pojo.SysSchedule;

import java.util.List;

public class SysScheduleDaoImpl extends BaseDao implements SysScheduleDao {
    /**
     * 添加一个日程
     * @param schedule
     * @return
     */
    @Override
     public int  addSchedule(SysSchedule schedule) {
        String sql = "insert into sys_schedule(uid,title,completed) values(?,?,?)";
        int rows = baseUpdate(sql,schedule.getUid(),schedule.getTitle(),schedule.getCompleted());
         return rows;
    }
    /**
     * 删除一个日程
     * @param schedule
     * @return
     */
    @Override
    public int deleteSchedule(SysSchedule schedule) {
        String sql = "delete from sys_schedule(uid,title,completed) where id=?";
        int rows = baseUpdate(sql,schedule.getSid());
        return rows;
    }

    /**
     * 查询一个日程
     * @param schedule
     * @return
     */
    @Override
    public SysSchedule querySchedule(SysSchedule  schedule){
        String sql = "select * from sys_schedule where uid = ?";
        SysSchedule sysSchedule = baseQueryObject(SysSchedule.class, sql, schedule.getUid());
        return sysSchedule;

    }
    /**
     * 查询所有日程
     * @return
     */
    @Override
    public List<SysSchedule> queryAllSchedule(){
        String sql = "select * from sys_schedule";
        List<SysSchedule> schedules = baseQuery(SysSchedule.class, sql);
        return schedules;
    }
    /**
     * 根据用户id查询所有日程
     * @param uid
     * @return
     */
    @Override
    public  List<SysSchedule> findAllScheduleByUid(Integer uid){
        String sql = "select * from sys_schedule where uid = ?";
        List<SysSchedule> list = baseQuery(SysSchedule.class, sql, uid);
        return list;
    }
    /**
     * 添加默认日程
     * @param uid
     * @return
     */
    @Override
    public Integer addDefaultSchedule(Integer uid){
        String sql = "insert into sys_schedule vales (DEFULT,uid,'',0) ";
        return baseUpdate(sql,uid);
    }
    /**
     * 修改一个日程
     * @param schedule
     * @return
     */
    @Override
    public Integer  updateSchedule(SysSchedule schedule){
        String sql = "update sys_schedule set title=?, completed=? where sid=?";
        int rows = baseUpdate(sql,schedule.getTitle(),schedule.getCompleted(),schedule.getSid());
        return rows;
    }
    /**
     * 删除一个日程
     * @param sid
     * @return
     */

    @Override
    public Integer removeSchedule(Integer sid){
        String sql = "delete from sys_schedule where sid=?";
        int rows = baseUpdate(sql,sid);
        return rows;
    }
}
